package main

import (
	"JoDocker/container"
	"fmt"
	"github.com/Sirupsen/logrus"
	"os"
)

func removeContainer(containerName string) {
	containerInfo, err := getContainerInfoByName(containerName)
	if err != nil {
		logrus.Errorf("Get container %s info error %v", containerName, err)
		return
	}
	// 只能删除停止的容器
	if containerInfo.Status != container.STOP {
		logrus.Errorf("Couldn't remove running container")
		return
	}
	// 删除容器信息
	dirPath := fmt.Sprintf(container.DefaultInfoLocation, containerName)
	if err := os.RemoveAll(dirPath); err != nil {
		logrus.Errorf("Remove file %s error %v", dirPath, err)
		return
	}
}
